/*     */ package com.zimbra.cs.mailclient.imap;
/*     */ 
/*     */ import com.google.common.base.Objects;
/*     */ import com.google.common.base.Objects.ToStringHelper;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class MailboxInfo
/*     */   implements ResponseHandler
/*     */ {
/*     */   private String name;
/*     */   private Flags flags;
/*     */   private Flags permanentFlags;
/*  31 */   private long exists = -1L;
/*  32 */   private long recent = -1L;
/*  33 */   private long uidNext = -1L;
/*  34 */   private long uidValidity = -1L;
/*  35 */   private long unseen = -1L;
/*     */   private CAtom access;
/*     */   
/*     */   public MailboxInfo(String name) {
/*  39 */     this.name = name;
/*     */   }
/*     */   
/*     */   public MailboxInfo(MailboxInfo mb) {
/*  43 */     this.name = mb.name;
/*  44 */     this.flags = mb.flags;
/*  45 */     this.permanentFlags = mb.permanentFlags;
/*  46 */     this.exists = mb.exists;
/*  47 */     this.recent = mb.recent;
/*  48 */     this.uidNext = mb.uidNext;
/*  49 */     this.uidValidity = mb.uidValidity;
/*  50 */     this.unseen = mb.unseen;
/*  51 */     this.access = mb.access;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private MailboxInfo() {}
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static MailboxInfo readStatus(ImapInputStream is)
/*     */     throws IOException
/*     */   {
/*  66 */     MailboxInfo mbox = new MailboxInfo();
/*  67 */     mbox.parseStatus(is);
/*  68 */     return mbox;
/*     */   }
/*     */   
/*     */   private void parseStatus(ImapInputStream is) throws IOException {
/*  72 */     this.name = MailboxName.decode(is.readAString()).toString();
/*     */     
/*  74 */     if ((is.peek() == 40) || (is.peek() == 41))
/*     */     {
/*  76 */       this.name += is.readText(" ");
/*     */     }
/*     */     
/*  79 */     String remaining = is.readText("(");
/*  80 */     if (remaining.trim().length() > 0) {
/*  81 */       this.name += remaining.substring(0, remaining.length() - 1);
/*     */     }
/*  83 */     is.skipChar('(');
/*  84 */     while (!is.match(')')) {
/*  85 */       Atom attr = is.readAtom();
/*  86 */       is.skipSpaces();
/*  87 */       switch (attr.getCAtom()) {
/*     */       case MESSAGES: 
/*  89 */         this.exists = is.readNumber();
/*  90 */         break;
/*     */       case RECENT: 
/*  92 */         this.recent = is.readNumber();
/*  93 */         break;
/*     */       case UIDNEXT: 
/*  95 */         this.uidNext = is.readNumber();
/*  96 */         break;
/*     */       case UIDVALIDITY: 
/*  98 */         this.uidValidity = is.readNumber();
/*  99 */         break;
/*     */       case UNSEEN: 
/* 101 */         this.unseen = is.readNumber();
/* 102 */         break;
/*     */       default: 
/* 104 */         ZimbraLog.imap_client.debug("Ignoring invalid STATUS response attribute: %s", new Object[] { attr });
/*     */       }
/* 106 */       is.skipSpaces();
/*     */     }
/*     */   }
/*     */   
/*     */   public void handleResponse(ImapResponse res)
/*     */   {
/* 112 */     switch (res.getCCode()) {
/*     */     case EXISTS: 
/* 114 */       this.exists = res.getNumber();
/* 115 */       break;
/*     */     case RECENT: 
/* 117 */       this.recent = res.getNumber();
/* 118 */       break;
/*     */     case FLAGS: 
/* 120 */       this.flags = ((Flags)res.getData());
/* 121 */       break;
/*     */     case OK: 
/* 123 */       handleResponseText(res.getResponseText());
/*     */     }
/*     */   }
/*     */   
/*     */   private void handleResponseText(ResponseText rt)
/*     */   {
/*     */     long n;
/* 130 */     switch (rt.getCCode()) {
/*     */     case UNSEEN: 
/* 132 */       this.unseen = ((Long)rt.getData()).longValue();
/* 133 */       break;
/*     */     case UIDNEXT: 
/* 135 */       n = ((Long)rt.getData()).longValue();
/* 136 */       if (n > 0L) this.uidNext = n;
/*     */       break;
/*     */     case UIDVALIDITY: 
/* 139 */       n = ((Long)rt.getData()).longValue();
/* 140 */       if (n > 0L) this.uidValidity = n;
/*     */       break;
/*     */     case PERMANENTFLAGS: 
/* 143 */       this.permanentFlags = ((Flags)rt.getData());
/* 144 */       break;
/*     */     case READ_WRITE: 
/* 146 */       this.access = CAtom.READ_WRITE;
/* 147 */       break;
/*     */     case READ_ONLY: 
/* 149 */       this.access = CAtom.READ_ONLY;
/*     */     }
/*     */     
/*     */   }
/*     */   
/* 154 */   public String getName() { return this.name; }
/* 155 */   public Flags getFlags() { return this.flags; }
/* 156 */   public Flags getPermanentFlags() { return this.permanentFlags; }
/* 157 */   public long getExists() { return this.exists; }
/* 158 */   public long getRecent() { return this.recent; }
/* 159 */   public long getUidNext() { return this.uidNext; }
/* 160 */   public long getUidValidity() { return this.uidValidity; }
/* 161 */   public long getUnseen() { return this.unseen; }
/* 162 */   public boolean isReadOnly() { return this.access == CAtom.READ_ONLY; }
/* 163 */   public boolean isReadWrite() { return this.access == CAtom.READ_WRITE; }
/*     */   
/* 165 */   public void setName(String name) { this.name = name; }
/*     */   
/*     */   public void setUidValidity(long uidValidity) {
/* 168 */     this.uidValidity = uidValidity;
/*     */   }
/*     */   
/*     */   public void setExists(int exists) {
/* 172 */     this.exists = exists;
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/* 177 */     return Objects.toStringHelper(this).add("name", this.name != null ? new MailboxName(this.name).encode() : null).add("exists", this.exists).add("recent", this.recent).add("unseen", this.unseen).add("flags", this.flags).add("permanent_flags", this.permanentFlags).add("uid_next", this.uidNext).add("uid_validity", this.uidValidity).add("access", this.access).toString();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/imap/MailboxInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */